package com.hopedove.quanlitycheck.activity;


import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;

import com.hopedove.base.BaseActivity;
import com.hopedove.quanlitycheck.R;
import com.hopedove.quanlitycheck.adapter.MateriaAdapter;
import com.hopedove.quanlitycheck.entity.MateriaEntity;
import com.hopedove.quanlitycheck.utils.QualitySharedPrefUtil;
import com.hopedove.view.SimpleDialog;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@SuppressLint("UseSparseArrays")
public class MaterialInfoActivity extends BaseActivity implements OnClickListener {

    List<MateriaEntity> mMaterialList = new ArrayList<>();
    String mUserbean = "";
    MateriaAdapter mAdapter;

    public static void actionStart(Context context, List<MateriaEntity> materialList) {
        Intent intent = new Intent(context, MaterialInfoActivity.class);
        intent.putExtra("materialList", (Serializable) materialList);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.quality_activity_material_info);
        if (getIntent() != null) {
            mMaterialList = (List<MateriaEntity>) getIntent().getSerializableExtra("materialList");
        }
        mUserbean = (String) QualitySharedPrefUtil.getValue(this, QualitySharedPrefUtil.USERBEAN, "");
        findViewById(R.id.call_img).setOnClickListener(this);
        findViewById(R.id.back_img).setOnClickListener(this);

        ListView listView = findViewById(R.id.info_listview);

        mAdapter = new MateriaAdapter(this, mMaterialList);
        listView.setAdapter(mAdapter);
    }


    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.call_img) {
            MateriaEntity materiaEntity = null;
            for (MateriaEntity entity :
                    mMaterialList) {
                if (entity.isSelect()) {
                    materiaEntity = entity;
                }
            }
            if (materiaEntity == null) {
                SimpleDialog.show(this, "请选择一条原料信息！");
                return;
            }
            Intent intent = new Intent();
            intent.putExtra("material", materiaEntity);
            setResult(RESULT_OK, intent);//设置resultCode
            finish();
        } else if (v.getId() == R.id.back_img) {
            finish();
        }
    }


}

